package com.example.rmiprovidedemo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.OutputStream;

@Slf4j
@RestController
@RequestMapping("class")
public class ClassController {

    @GetMapping(value = "/get")
    public void get(HttpServletResponse response) {
        String file = "E:\\code\\java\\myDiy\\springbootjdk8demo\\rmidemo\\rmicommondemo\\target\\classes\\com\\example\\rmicommondemo\\model\\ReferenceObjectFactory.class";
        FileInputStream inputStream = null;
        OutputStream os = null;
        try {
            inputStream = new FileInputStream(file);
            byte[] data = new byte[inputStream.available()];
            inputStream.read(data);
            os = response.getOutputStream();
            os.write(data);
            os.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            // 省略流的判断关闭；
        }
    }
}